package com.mall.service.order.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.commons.common.CommonPage;
import com.mall.commons.common.CommonResult;
import com.mall.model.domain.OmsOrderReturnReason;
import com.mall.service.order.service.OmsOrderReturnReasonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.util.List;

@RestController
@RequestMapping("/returnReason")
public class OmsOrderReturnReasonController {

    @Autowired
    OmsOrderReturnReasonService omsOrderReturnReasonService;

    /**
     * 分页查询退货原因
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public CommonResult<CommonPage> getReturnReason(@RequestParam(defaultValue = "1") Integer pageNum,
                                                    @RequestParam(defaultValue = "10") Integer pageSize){
        Page<OmsOrderReturnReason> page = new Page<>(pageNum,pageSize);
        omsOrderReturnReasonService.page(page);
        CommonPage page1 = CommonPage.getPage(page);
        return CommonResult.success(page1);
    }

    /**
     *获取单个退货原因详情信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public CommonResult<OmsOrderReturnReason> getReturnReasonInfo(@PathVariable Long id){
        OmsOrderReturnReason omsOrderReturnReason = omsOrderReturnReasonService.getByInfo(id);
        return CommonResult.success(omsOrderReturnReason);
    }

    /**
     *添加退货原因
     * @param returnReason
     * @return
     */
    @PostMapping("/create")
    public CommonResult add(@RequestBody OmsOrderReturnReason returnReason){
        omsOrderReturnReasonService.save(returnReason);
        return CommonResult.success("添加成功");
    }

    /**
     *批量删除退货原因
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public CommonResult del(@RequestParam List<Long> ids){
        omsOrderReturnReasonService.removeByIds(ids);
        return CommonResult.success("删除成功");
    }

    /**
     * 修改退货原因启用状态
     * @param ids
     * @param status
     * @return
     */
    @PostMapping("/update/status")
    public CommonResult updateStatus(@RequestParam List<Long> ids, int status){
        omsOrderReturnReasonService.updateWithStatus(ids,status);
        return CommonResult.success("修改成功");
    }

    /**
     * 修改退货原因
     * @param id
     * @param omsOrderReturnReason
     * @return
     */
    @PostMapping("/update/{id}")
    public CommonResult updateReason(@PathVariable Long id,@RequestBody OmsOrderReturnReason omsOrderReturnReason){
        omsOrderReturnReasonService.updateWhitReason(id,omsOrderReturnReason);
        return CommonResult.success("修改成功");
    }
}
